/*
 * Copyright (C) RT, 2017 by kiterunner_t
 * TO THE HAPPY FEW
 */

package com.zgys.mes.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class Log {
    private static final Logger logger = LoggerFactory.getLogger(Log.class);
    private static boolean isTrace;


    public static void init(boolean trace) {
        isTrace = trace;
    }


    public static void info(String s, Object... objects) {
        s = getTrace(s);
        logger.info(s, objects);
    }


    public static void debug(String s, Object... objects) {
        s = getTrace(s);
        logger.debug(s, objects);
    }


    public static void error(String s, Object... objects){
        s = getTrace(s);
        logger.error(s, objects);
    }


    public static void warn(String s, Object... objects) {
        s = getTrace(s);
        logger.warn(s, objects);
    }


    public static void setLevel(String level) {
    }


    private static String getTrace(String format) {
        if (isTrace == false) {
            return format;
        }

        try {
            StackTraceElement parent = Thread.currentThread().getStackTrace()[3];
            format = String.format("[%s.%s, %d] %s", parent.getClassName(),
                    parent.getMethodName(),
                    parent.getLineNumber(), format);

        } catch (Exception ex) {
            // do nothing ...
        }

        return format;
    }
}

